package live.jialing.sip.contact.student.domain;

import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import com.google.common.collect.Lists;
import live.jialing.sip.base.domain.School;
import live.jialing.sip.base.domain.Student;
import live.jialing.sip.contact.domain.ContactGroup;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import javax.persistence.*;
import java.util.List;

/**
 * 家校通讯录中的分组<br>
 * student contact group
 */
@Setter
@Getter
@ToString
@Entity
@DiscriminatorValue("student")
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id", scope = StudentGroup.class)
public class StudentGroup extends ContactGroup {

    /**
     * 组的所在学校
     */
    @ManyToOne( fetch = FetchType.LAZY, optional = false)
    @JoinColumn(name = "ower_company_id",updatable = false)
    private School school;

    /**
     * 学生
     */
    @ManyToMany(fetch = FetchType.LAZY)
    @JoinTable(name = "contact_group_student_relation",//被关联表
            inverseJoinColumns = {@JoinColumn(name = "student_id", referencedColumnName = "id")},//被维护端外键
            joinColumns = {@JoinColumn(name = "group_id", referencedColumnName = "id")})//维护端外键
    private List<Student> students = Lists.newArrayList();

}
